/*
 * @Author: hifishroom
 * @Date: 2021-09-18 10:36:04
 * @LastEditTime: 2021-09-23 19:48:31
 * @FilePath: \jdmall\pages\classify\classify.js
 */
// pages/classify/classify.js
const App = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    classifyData: [],
    currentIndex: 0,
    textArr: ["苏打水", "农夫三拳", "苹果手机"],
    flag: true,
    isShow: false,
    title: "家电套装",
    upFlag: true,
    containerTop: 0,
    leftScrollTop: 0,
  },
  // 子项点击事件
  detailClick() {
    wx.navigateTo({
      //目的页面地址
      url: "./children/shoplist/shoplist",
    });
  },
  // 侧边导航点击事件
  sideBarItemClick(event) {
    let that = this;
    let index = event.currentTarget.dataset.index;
    let title = that.data.classifyData[index + 1].type_name;
    that.setData({
      currentIndex: index,
      isShow: false,
      flag: true,
      title: title,
    });
    wx.getSystemInfo({
      success: (res) => {
        that.setData({
          leftScrollTop: event.currentTarget.offsetTop - res.windowHeight / 2,
        });
      },
    });
  },
  //  下拉刷新被触发事件
  upClick(e) {
    let that = this;
    let index = that.data.currentIndex;
    if (index === 0) {
      that.setData({
        currentIndex: 0,
        isShow: false,
        flag: true,
        upFlag: false,
        title: "家具套装",
      });
    } else {
      let title = that.data.classifyData[index].type_name;
      that.setData({
        isShow: false,
        flag: true,
        title: title,
      });
      setTimeout(() => {
        that.setData({
          upFlag: false,
          currentIndex: index-1,
        });
      }, 2000);
    }
    that.setData({
      upFlag: true,
    });
  },
  // 滚动到底部触发事件
  lower(e) {
    let that = this;
    that.setData({
      isShow: true,
    });
    setTimeout(() => {
      that.setData({
        flag: false,
      });
    }, 2000);
  },
  // 去往下一页点击事件
  nextClick() {
    let that = this;
    let index = that.data.currentIndex + 1;
    let title = that.data.classifyData[index + 1].type_name;
    that.setData({
      currentIndex: index,
      title: title,
      isShow: false,
      flag:true,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //自定义头部方法
    this.setData({
      navH: App.globalData.navHeight,
    });
    let that = this;
    wx.request({
      url:"http://api_devs.wanxikeji.cn/api/goodType",

      method: "post",

      success: function (res) {
        let data = res.data.data;
        let arr = data.map((item) => {
          let tempArr = {};
          tempArr.type_name = item.type_name;
          tempArr.id = item.good_type_id;
          tempArr.children = [];
          return tempArr;
        });
        let tempArr = data.filter((item) => {
          if (item.parent_id) {
            return item.pic;
          }
        });
        arr[0].children.push({ name: "老人机", pic: tempArr[40].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[37].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[41].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[16].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[17].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[18].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[19].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[20].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[21].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[22].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[23].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[24].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[25].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[26].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[27].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[28].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[29].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[30].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[31].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[32].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[33].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[31].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[32].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[33].pic });
        arr[0].children.push({ name: "老人机", pic: tempArr[31].pic });
        arr[0].children.push({ name: "小米", pic: tempArr[32].pic });
        arr[0].children.push({ name: "华为", pic: tempArr[33].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[1].children.push({ name: "键盘", pic: tempArr[3].pic });
        arr[1].children.push({ name: "鼠标", pic: tempArr[4].pic });
        arr[1].children.push({ name: "酱油", pic: tempArr[5].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[2].children.push({ name: "大米", pic: tempArr[6].pic });
        arr[2].children.push({ name: "醋", pic: tempArr[7].pic });
        arr[2].children.push({ name: "机械键盘", pic: tempArr[8].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[3].children.push({ name: "view", pic: tempArr[9].pic });
        arr[3].children.push({ name: "上衣", pic: tempArr[13].pic });
        arr[3].children.push({ name: "下装", pic: tempArr[11].pic });
        arr[4].children.push({ name: "裤子", pic: tempArr[12].pic });
        arr[4].children.push({ name: "衬衣", pic: tempArr[13].pic });
        arr[4].children.push({ name: "屏高", pic: tempArr[14].pic });
        arr[4].children.push({ name: "苹果", pic: tempArr[15].pic });
        arr[4].children.push({ name: "裤子", pic: tempArr[12].pic });
        arr[4].children.push({ name: "衬衣", pic: tempArr[13].pic });
        arr[4].children.push({ name: "屏高", pic: tempArr[14].pic });
        arr[4].children.push({ name: "苹果", pic: tempArr[15].pic });
        arr[4].children.push({ name: "裤子", pic: tempArr[12].pic });
        arr[4].children.push({ name: "衬衣", pic: tempArr[13].pic });
        arr[4].children.push({ name: "屏高", pic: tempArr[14].pic });
        arr[4].children.push({ name: "苹果", pic: tempArr[15].pic });
        arr[4].children.push({ name: "裤子", pic: tempArr[12].pic });
        arr[4].children.push({ name: "衬衣", pic: tempArr[13].pic });
        arr[4].children.push({ name: "屏高", pic: tempArr[14].pic });
        arr[4].children.push({ name: "苹果", pic: tempArr[15].pic });
        arr[4].children.push({ name: "裤子", pic: tempArr[12].pic });
        arr[4].children.push({ name: "衬衣", pic: tempArr[13].pic });
        arr[4].children.push({ name: "屏高", pic: tempArr[14].pic });
        arr[4].children.push({ name: "苹果", pic: tempArr[15].pic });
        arr = arr.splice(0, 21);
        that.setData({ classifyData: arr });
      },
      fail: function (err) {
        console.log(err);
      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 配合自定义tabBar切换
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1,
      });
    }
  },
  globalData: {
    userInfo: null,
    navHeight: 0,
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
